﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DocumentFormat.OpenXml.Spreadsheet;
using FileManager.ViewModel;

namespace FileManager
{
    /// <summary>
    /// PicCompare.xaml 的交互逻辑
    /// </summary>
    public partial class PicCompareWindow : Window
    {
        public PicCompareWindow(string oldPath,BitmapImage newImage)
        {
            InitializeComponent();
            model = new PicCompareViewModel(this);
            byte[] bytes = File.ReadAllBytes(oldPath);

            MemoryStream ms = new MemoryStream(bytes);
            var oldBmp=new BitmapImage();
            oldBmp.BeginInit();
            oldBmp.CacheOption = BitmapCacheOption.OnLoad;
            oldBmp.StreamSource = ms;
            oldBmp.EndInit();

            model.OldImage = oldBmp;
            model.NewImage = newImage;
            DataContext = model;
            
        }
        private PicCompareViewModel model { get; set; }
        private void ReplaceBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
        private void Window_Closed(object sender, EventArgs e)
        {
            if (model.OldImage != null)
                model.OldImage.Freeze();
            if (model.NewImage != null)
                model.NewImage.Freeze();
            
        }
    }
}
